package ics314;

import java.awt.Point;

public class Airplane implements PositionalEntity{

	private String name;
	
	private int heading;
	private int speed;
	
	private Point position;
	
	public Airplane(String name, Point position){
		this.name = name;
		this.position = position;
		this.heading = 0;
		this.speed = 0;
	}

	public Airplane(String name){
		this(name, new Point(0, 0));
	}
	
	public Airplane(String name, int x, int y) {
		this(name, new Point(x, y));
	}
	
	public int getHeading(){
		return this.heading;
	}
	
	public String getName(){
		return this.name;
	}
	
	public void setHeading(int newHeading){
		while(newHeading < 0){
			newHeading += 360;
		}
		this.heading = newHeading % 360;
	}
	
	public void setSpeed(int newSpeed) {
		this.speed = newSpeed;
	}
	
	public int getSpeed() {
		return this.speed;
	}
	
	@Override
	public Point getPosition() {
		return position;
	}
	
	public void move() {
		double dx = Math.sin(Math.toRadians(heading)) * speed;
		double dy = Math.cos(Math.toRadians(heading)) * speed;
		
		position.setLocation(position.getX() + dx, position.getY() + dy);
	}
}
